Ext.define('PJ.view.messagemanagement.PreReceiverList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.preReceiverList'],
    isHavePage:false,
    
    initComponent: function(){
    	var me = this;
        this.columns = [{
        	header: '登录号',
        	dataIndex: 'loginID',
        	width: 90
        },{
        	header: '姓名',
        	dataIndex: 'userName',
        	width: 110
        }, {
        	header: '单位',
        	dataIndex: 'depName',
        	flex: 1,
            minWidth: 110
        }, {
            header: '角色',
            dataIndex: 'roleName',
            width: 110
        }/*, {
            header: '选取状态',
            dataIndex: 'selectState',
            width: 90,
    		renderer: function(value, metaData, record){
    			metaData.tdAttr = 'data-qtip="' + value + '"';
    			if(value==1){
    				return "<span style='color:green'>已选取</span>"
    			}else if(value==2){
    				return "<span style='color:red'>未选取</span>"
    			}
    		}
        }*/];
        this.store = Ext.create('PJ.' + prototype + '.messagemanagement.PreReceiverList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },

    // 新增
    onAddClick: function(){
        var me = this;
        var win = me.up('window');
        var records = me.getSelectionModel().getSelection();
       /* win.down("receiverList").getSelectionModel().selectAll();
        var receiver_rec = win.down("receiverList").getSelectionModel().getSelection();*/
        var userId = new Array();
        /*if(me.up('window').userId.length !=1 && me.up('window').userId[0] != ""){
        	userId = me.up('window').userId;
        }*/
        for(var i = 0;i<records.length;i++){
        	userId.push(records[i].get("userId"));
        }
        /*for(var j = 0;j<receiver_rec.length;j++){
        	userId.push(receiver_rec[j].get("userId"));
        }*/
        Ext.Msg.alert('通知', '添加成功！', function(){
        	var form = win.grid.down("form").getForm();
        	var teacherIdStr = form.findField("receiveUserId");
			var teacherNameStr = form.findField("receiveName");
			var teacherListIds = new Array();
			var teacherListNames = new Array();
			teacherIdStr.setValue("");
			teacherNameStr.setValue("");
			for(var j = 0 ; j < records.length; j++){
				teacherListIds.push(records[j].get('userId'));
				teacherListNames.push(records[j].get('userName'));
				
			}
			teacherIdStr.setValue(teacherListIds);
			teacherNameStr.setValue(teacherListNames);
			win.close();
        	/*var store = me.getStore();
            var params = store.proxy.extraParams;
            var newParams = {
            		searchSelectedUserIds:userId,
            		searchClassIds: me.up('window').classId,
            		searchSelectState:2
            };
            Ext.apply(params, newParams);
            store.load();
            
            var stroe_rec = win.down("receiverList").getStore();
            var params_rec = stroe_rec.proxy.extraParams;
            var newParams_rec = {
            		searchSelectedUserIds:userId,
            		searchClassIds: me.up('window').classId,
            		searchSelectState:1
            };
            Ext.apply(params_rec, newParams_rec);
            stroe_rec.load();*/
        });
    
    },
    listeners: {
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + "Add").setDisabled(selected.length === 0);
    	},
        viewready: function(){
        	var me = this;
            this.addDocked([/*{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: true,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80,
                    maxLength: 100
                },
                items: [{
                	xtype: "textfield",
                    fieldLabel: "登录号",
                    name: "searchLoginId",
                    emptyText: "请输入登录号"
                },{
                	xtype: "textfield",
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名"
                },{
                	xtype: "textfield",
                    fieldLabel: "单位",
                    name: "searchDepName",
                    emptyText: "请输入单位"
                },{
    				xtype: "textfield",
    				fieldLabel: '角色',
    				name: "searchRoleCode",
    				maxLength: "50",
    				emptyText: "请输入角色"
    			}],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                    		searchClassIds: me.up('window').classId,
                    		searchSelectedUserIds: me.up('window').userId,
                    		searchSelectState:2
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                grid: this
            }, */{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
    				text: '选取',
    				iconCls: 'addIco',
    				itemId: this.oldId + "Add",
    				scope: this,
    				disabled:true,
    				handler: this.onAddClick
    			}, "->", "->", this.countSelectPanel]
            }]);
            var me = this;
            // 触发权限过滤事件
            me.fireEvent("permission", this);
            var params = me.store.proxy.extraParams;
            var newParams = {
            		searchClassIds: me.up('window').classId,
            		searchSelectedUserIds: me.up('window').userId
            };
            Ext.apply(params, newParams);
            this.store.isLoad = true;
            this.store.load(function(){
            	var userId =  me.up('window').userId;
            	if(userId.length == 1 && userId[0]==""){
            		return;
            	}
            	me.getSelectionModel().selectAll();
            	var records = me.getSelectionModel().getSelection();
//            	me.getSelectionModel().deselect(records);
            	for(var i=0;i<records.length;i++){
            		var flag = true;
            		for(var j=0;j<userId.length;j++){
            			if(userId[j] == records[i].data.userId){
            				flag = false;
            				continue;
            			}
            		}
        			if(flag){
        				me.getSelectionModel().deselect(records[i]);
        			}
            	}
            });
        }
    }
});
